/**
 * 
 * @param {*} template 
 * @param {*} replaceObject 
 */
function tplReplace (template, replaceObject) {
    return template().replace(/{{(.*?)}}/g, (node, key) => {
        return replaceObject[key];
    })
}

/**
 * 获取url地址栏携带的参数
 * @param {键名} key 
 */
function getUrlQueryValue (key) {
	const reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)', 'i'),
	      res = window.location.search.substr(1).match(reg);

	return res != null ? decodeURIComponent(res[2]) : null;
}

/**
 * 
 * @param {事件源对象} ev 
 */
function getTarget (ev) {
    const e = ev || window.event;
    return e.target || e.srcElement;
}

export{
    tplReplace, 
    getUrlQueryValue,
    getTarget
}